<?php
namespace Admin\Model;
use Think\Model;

class ExpertModel extends AbstractModel {

	protected $results = array();
	
	public $_validate = array(
        array('TrueName','require','请选输入姓名',Model::MUST_VALIDATE),
        array('Sex','number','请选择工性别',Model::MUST_VALIDATE),
        array('Phone','number','请选输入手机号码',Model::MUST_VALIDATE)
    );
	
	
	protected $_auto = array(
    	array('AddTime', 'getAddTime',3,'callback')
  	);
    
    public function getAddTime(){
		return date('Y-m-d H:i:s');
	}
	
	public function Myadd(){
		if(!$this->create()){
			$this->results['msg'] = $this->getError();
			$this->results['state'] = 0;
		}else{
			$res = $this->add();
			if($res) {
				$this->results['state'] = 1;
				$this->results['msg'] = "添加成功！";
				$this->results['id'] = $res;
			}else{
				$this->results['state'] = 0;
				$this->results['msg'] = "添加错误！";
			}
		}
		return $this->results;
	}
	
	
	public function Myupdata(){
		if(!$this->create()){
			$this->results['msg'] = $this->getError();
			$this->results['state'] = 0;
		}else{
			$res = $this->save();
			if($res) {
				$this->results['state'] = 1;
				$this->results['msg'] = "修改成功！";
				$this->results['id'] = $res;
			}else{
				$this->results['state'] = 0;
				$this->results['msg'] = "修改错误！";
			}
		}
		return $this->results;
	}
	
	
	public function Myshow($parmArr){
		$where = " 1 ";
		foreach($parmArr AS $key => $value){
			$where .= " AND $key = '$value'"; 
		}
		$sql = "SELECT * FROM expert AS a WHERE $where";
		$res = $this->query($sql);
		return $res;
	}
	
	
	public function MyshowList(){
		$where = "";
		$keyword = I('keyword');
		if(!empty($keyword)){
            $where['TrueName|Phone|EMail|CardNO|Major'] = array('like','%'.$keyword.'%');
        }
		$return = array();
		$count = $this->where($where)->count();
	    $page = $this->Mypage($count, 8);
	    $fields = 'TrueName,Sex,Phone,Major,Title,ID';
		$res = $this->where($where)->field($fields)->limit($page->firstRow.','.$page->listRows)->select();
		$return['list'] = $res;
		$return['page'] = $page->show('Admin');
		return $return;
	}
	
	
	public function getProjectList(){
		$depat = M("project");
		//$where['IsDel'] = 0;
		return $depat->field('ID,Name')->where()->select();
	}
	
}

?>				